package edu.sctu.yueding.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import edu.sctu.yueding.R;
import edu.sctu.yueding.bean.Route;

/**
 * Created by Administrator on 2016/8/15.
 */
public class ChooseLineListViewAdapter extends BaseExpandableListAdapter {

    private Activity activity;
    private List<Route> roteDataList;
    private ExpandableListView expandListView;
    private ImageView groupImageLogo;
    private TextView groupText, childText;

    public ChooseLineListViewAdapter(Activity activity, List<Route> roteDataList) {
        this.activity = activity;
        this.roteDataList = roteDataList;
    }

    //设置组视图的显示文字

//    private String[] generalsTypes = new String[]{type1, type2, type3, type4};


    @Override
    public int getGroupCount() {
        return roteDataList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return roteDataList.get(groupPosition).getRouteList().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return roteDataList.get(groupPosition).getName();
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
//        if (groupPosition == 0) {
//            return lDataList.get(childPosition);
//        } else if (groupPosition == 1) {
//            return tDataList.get(childPosition);
//        } else if (groupPosition == 2) {
//            return gDataList.get(childPosition);
//        } else {
//            return qDataList.get(childPosition);
//        }

        return roteDataList.get(groupPosition).getRouteList().get(childPosition);

//        return generals[groupPosition][childPosition];
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        System.out.println("group:" + groupPosition + "child:" + childPosition);
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.item_group_choose_line, null);

        groupImageLogo = (ImageView) convertView.findViewById(R.id.group_choose_line_logo);
        groupText = (TextView) convertView.findViewById(R.id.group_choose_line_text);

        groupText.setText(getGroup(groupPosition).toString());

        if (isExpanded) {
            groupImageLogo.setImageResource(R.drawable.list_item_collapse);
        } else {
            groupImageLogo.setImageResource(R.drawable.list_item_expand);
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.item_child_choose_line, null);
        childText = (TextView) convertView.findViewById(R.id.child_choose_line_text);


//        if (groupPosition == 0) {
//            childText.setText(lDataList.get(childPosition).getIntroduction());
//        } else if (groupPosition == 1) {
//            childText.setText(tDataList.get(childPosition).getIntroduction());
//        } else if (groupPosition == 2) {
//            childText.setText(gDataList.get(childPosition).getIntroduction());
//        } else {
//            childText.setText(qDataList.get(childPosition).getIntroduction());
//        }
//
        childText.setText(roteDataList.get(groupPosition).getRouteList().get(childPosition).getIntroduction());

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}

